<?php

	/**
	* @package admin
	* @desc Page for showing the image of the park which is contained inside our database.
	*/
	session_start();
	
	/**
	* @desc This include file connects to the database.
	*/
	require 'includes/connect.inc';
	
	$park_id = $_GET["id"];
	
	$query = "SELECT id, name, type, size, file FROM pictures WHERE id = $park_id";
	
	$result = mysql_query($query, $connection);
	if(mysql_num_rows($result) > 0)
	{
		$row = mysql_fetch_array($result);
		
		$pic = imagecreatefromstring($row['file']);
		if ($pic !== false)
		{
			header("Content-Type: image/".$row['type']);   // to use it later in HTTP headers
			if($row['type'] == "png") // checking image type
				imagepng($pic);
			else if(($row['type'] == "jpeg") || ($row['type'] == "jpg"))
				imagejpeg($pic);
			else if($row['type'] == "gif")
				imagegif($pic);
		
			imagedestroy($pic);
		}
	}
	/**
	* @desc This include file disconnects from the database.
	*/
	require 'disconnect.inc';
?>